package com.github.chain.admin.server.controller;

import com.github.chain.admin.common.domain.Menu;
import com.github.chain.admin.common.request.MenuRequest;
import com.github.chain.admin.server.service.MenuService;
import com.github.framework.core.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author AIQ
 * @date 2023/5/11
 * @project er-trader
 */
@RestController
public class MenuController {

    @Resource
    private MenuService menuService;

    @GetMapping("/findMenuByUserId/{userId}")
    Result<TreeMap<Long, Menu>> findMenuByUserId(@PathVariable("userId") Long userId){
        return menuService.findMenuByUserId(userId);
    }

    @PostMapping("/roleMenuAuthList/{id}")
    Result<List<Menu>> roleMenuAuthList(@PathVariable("id") Long id){
        return menuService.roleMenuAuthList(id);
    }

    @PostMapping("/findMenuList")
    Result<List<Menu>> findMenuList(@RequestBody MenuRequest menuRequest){
        return menuService.findMenuList(menuRequest);
    }

    @PostMapping("/findMenuListSort")
    Result<Map<Integer, String>> findMenuListSort(@RequestBody MenuRequest menuRequest){
        return menuService.findMenuListSort(menuRequest);
    }

    @PostMapping("/findMenuById/{id}")
    Result<Menu> findMenuById(@PathVariable("id") Long id){
        return menuService.findMenuById(id);
    }

    @PostMapping("/saveMenu")
    Result saveMenu(@RequestBody MenuRequest menuRequest){
        return menuService.saveMenu(menuRequest);
    }

    @PostMapping("/findMenuByMenuId/{id}")
    Result<Menu> findMenuByMenuId(@PathVariable("id") Long id){
        return menuService.findMenuByMenuId(id);
    }

    @PostMapping("/updateMenu")
    Result<Integer> updateMenu(@RequestBody MenuRequest menuRequest){
        return menuService.updateMenu(menuRequest);
    }

    @PostMapping("/deleteMenuByMenuId/{id}")
    Result<Integer> deleteMenuByMenuId(@PathVariable("id") Long id){
        return menuService.deleteMenuByMenuId(id);
    }
}
